package com.mpw.cloud.controller;


import com.mpw.cloud.entities.CommonResult;
import com.mpw.cloud.entities.Payment;
import com.mpw.cloud.service.PaymentService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @program:Cloud
 * @author: mpw
 * @Time: 2021/10/29  10:05
 * 微服务提供者
 **/
@RestController
@Slf4j
public class PaymentController {

    @Value("${server.port}")
    private String serverPort;

    @Resource
    private PaymentService paymentService;

    @PostMapping("payment/create")//写操作
    public CommonResult create(@RequestBody Payment payment){
        System.out.println(payment);
        int result= paymentService.create(payment);
        log.info("结果："+result);

        if (result>0){
            return new CommonResult(200,"插入成功,返回结果"+result+" 服务端口："+serverPort,result);
        }else{
            return new CommonResult(444,"插入失败",null);
        }
    }

    @GetMapping("/payment/get/{id}")//查操作
    public CommonResult<Payment> getPaymentById(@PathVariable("id")Long id){
        Payment payment= paymentService.getPaymentById(id);
        log.info("结果："+payment);

        if (payment!= null){
            return new CommonResult(200,"查询成功,返回结果  服务端口："+serverPort,payment);
        }else{
            return new CommonResult(444,"查询失败，不存在"+id,null);
        }
    }


}
